
capture log close
log using $log/AED_analysis_07_sensitivity_control, text replace

/* ------------------------------------------------------------------------------------ */
/* --- Sensitivity Analysis Table A.9 ------------------------------------------------- */
/* ------------------------------------------------------------------------------------ */ 


clear
clear matrix
clear mata
set maxvar 10000
set matsize 2000
set more off

set trace off
   
#d;
global xvars " vac_rate aloq   
				share_agriculture_avg share_industry_avg share_service_avg wanderungen_avg bip_avg 
				iza_alter_kat1 iza_alter_kat2 iza_alter_kat3 iza_alter_kat4 iza_sex iza_famstd
				i.iza_kind i.iza_abschluss_kat i.iza_ausb_kat
				iza_last_daily_income i.iza_beruf_kat
				iza_ende_last iza_vztz_last iza_zeit_la
				iza_sv_tminus1 iza_sv_tminus2 iza_sv_tminus3
				iza_lnwage_tminus1 iza_lnwage_tminus2 iza_lnwage_tminus3 
				i.year i.entry_m";
				#d cr
				
				
	#d;
global macro " vac_rate aloq   
				share_agriculture_avg share_industry_avg share_service_avg wanderungen_avg bip_avg 
				i.year i.entry_m";
				#d cr

				
#d;
global indv "   iza_alter_kat1 iza_alter_kat2 iza_alter_kat3 iza_alter_kat4 iza_sex iza_famstd
				i.iza_kind i.iza_abschluss_kat i.iza_ausb_kat
				iza_last_daily_income i.iza_beruf_kat
				iza_ende_last iza_vztz_last iza_zeit_la
				iza_sv_tminus1 iza_sv_tminus2 iza_sv_tminus3
				iza_lnwage_tminus1 iza_lnwage_tminus2 iza_lnwage_tminus3 
				i.year i.entry_m";
				#d cr
		
	
	
		use $data/data_est_border, clear
	
	
	
	keep if eintritt<=200805 & eintritt>=200706
	

	#d;
		egen month_sv1_24 = rsum(sv_tplus_1 sv_tplus_2 sv_tplus_3 sv_tplus_4 sv_tplus_5 sv_tplus_6 sv_tplus_7 sv_tplus_8 sv_tplus_9 sv_tplus_10 
		sv_tplus_11 sv_tplus_12 sv_tplus_13 sv_tplus_14 sv_tplus_15 sv_tplus_16 sv_tplus_17 sv_tplus_18 sv_tplus_19 sv_tplus_20 sv_tplus_21 sv_tplus_22 sv_tplus_23 sv_tplus_24)
		;
	
		egen earnings1_24 = rsum(daily_income_tplus_1 daily_income_tplus_2 daily_income_tplus_3 daily_income_tplus_4 daily_income_tplus_5
		daily_income_tplus_6 daily_income_tplus_7 daily_income_tplus_8 daily_income_tplus_9 daily_income_tplus_10 daily_income_tplus_11
		daily_income_tplus_12 daily_income_tplus_13 daily_income_tplus_14 daily_income_tplus_15 daily_income_tplus_16 
		daily_income_tplus_17 daily_income_tplus_18 daily_income_tplus_19 daily_income_tplus_20
		daily_income_tplus_21 daily_income_tplus_22 daily_income_tplus_23 daily_income_tplus_24);
		replace earnings1_24 = earnings1_24*30;
		#d cr
	
	
	
	
	
	
	foreach var in $outc {
		qui reg `var' log_intensity_alt $xvars pair_* [pw=1/fweight_reg], cluster(ba)
		matrix b=e(b)'
		matrix n=e(N)
		matrix v=e(V)
		matrix se=vecdiag(cholesky(diag(vecdiag(v[1..1,1..1]))))'
		qui sum `var'
		matrix m = r(mean)	
		matrix d1_`var'=b[1..1,1..1],se
		 
		qui reg `var' log_intensity_alt $season pair_* [pw=1/fweight_reg], cluster(ba)
		matrix b=e(b)'
		matrix n=e(N)
		matrix v=e(V)
		matrix se=vecdiag(cholesky(diag(vecdiag(v[1..1,1..1]))))'
		qui sum `var'
		matrix m = r(mean)	
		matrix d2_`var'=b[1..1,1..1],se
		
		qui reg `var' log_intensity_alt $macro pair_* [pw=1/fweight_reg], cluster(ba)
		matrix b=e(b)'
		matrix n=e(N)
		matrix v=e(V)
		matrix se=vecdiag(cholesky(diag(vecdiag(v[1..1,1..1]))))'
		qui sum `var'
		matrix m = r(mean)	
		matrix d3_`var'=b[1..1,1..1],se
		
		
		matrix top_`var' = d1_`var',d2_`var',d3_`var'
		
		
	}
	


matrix top = top_month_sv1_24\top_earnings1_24\top_umzugskosten_24


matrix colnames top = "Baseline" "SE" "Season" "SE" "Macro" "SE"


matrix rownames top = "Months employed" "Earnings" "Relocation assistance"


mal list top




log close
